﻿using LServer.Core.Utils;
using LServer.Model.Logic.DBModels;
using LServer.Model.Logic.Entitys;
using LServer.Model.Managers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Principal;
using System.Text;

namespace LServer.WebAccount.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        [HttpGet]
        public async Task<string> Get(long id) 
        {
            //AccountEntity accountEntity = new AccountEntity();
            //accountEntity.LFId = DBModelMgr.UniqueIDAccount.GetUniqueID(0);
            //accountEntity.UserName = "xxl";
            //accountEntity.Password = "123";

            //DBModelMgr.AccountDBModel.Add(accountEntity);

            //return accountEntity.LFId.ToString();
            AccountEntity account = await LFRedisHelp.LFCacheShellAsync<AccountEntity>("Account", id.ToString(), GetAccount);

            int status = 1;

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("{Status:");
            stringBuilder.Append(status);
            stringBuilder.Append(",Content:");
            stringBuilder.Append(Newtonsoft.Json.JsonConvert.SerializeObject(account)); 
            stringBuilder.Append("}");

            return stringBuilder.ToString();
        }

        private async Task<AccountEntity> GetAccount(string arg)
        {
            long yfId;
            long.TryParse(arg,out yfId);
            return await DBModelMgr.AccountDBModel.GetEntityAsync(yfId);
        }
    }
}
